<?php
/**
 *APINAME:
 *Developer:
 *Complete:
 */

namespace app\index\controller;


use app\common\controller\Basecontroller;
use app\common\controller\OssStorage;
use app\index\model\Classification;
use app\index\model\Official;
use app\index\model\User;
use app\validate\Vali;
use think\Request;

class PublicOff extends Basecontroller
{
    /**
     * 发布职位接口
     * ywh开发
     * @param Request $request
     * @param User $userModel
     * @param Vali $Validate
     * @param Official $official
     * @param Classification $classification
     * @return \think\response\Json
     */
    public function publicOff(Request $request , User $userModel , Vali $Validate , Official $official , Classification $classification){
        $userID = $this->getUserID();
        $companyID = json_decode($userModel->getComiDAttr($userID))->company_id;
        if (!$companyID) return $this->returnJson(self::ERROR,"非人事账号，发布失败");
        $off = [
            'user_id'                    =>       $userID,
            'company_id'             =>       $companyID,
            'official'                      =>      $request->post('official'),
            'off_area'                  =>      $request->post('offArea'),
            'official_describe'      =>      $request->post('describe'),
            'wordweek'               =>      $request->post('wordWeek'),
            'education'                 =>      $request->post('education'),
            'job_money'              =>      $request->post('jobMoney'),
            'requirement'              =>      $request->post('requirement'),
            'worktime'              =>      $request->post('worktime'),
            'create_time'             =>       time()
        ];
        if (!$Validate->scene('publicOff')->batch()->check($off)) return $this->returnJson(self::ERROR,'数据格式错误',$Validate->getError());
        $offID = $official->insertGetId($off);
        if (!$offID) return $this->returnJson(self::ERROR,'数据库错误');
        $class = [
            'class'          =>      $request->post('offType'),
            'official_id'   =>      $offID
        ];
        if (!$Validate->scene('offClass')->batch()->check($class)) return $this->returnJson(self::ERROR,'数据格式错误',$Validate->getError());
        if (!$classification->upOff($class)) return $this->returnJson(self::ERROR,'数据库错误');
        return $this->returnJson(self::JUMP,'发布成功',['offId' => $offID]);
    }
}